<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>滚轮事件（课程）</title>
    <style>
        /* *{
            transition: 0.2s;
        } */
        #box1{
            width: 100px;
            height: 100px;
            background-color: rgb(1, 187, 125);
        }
    </style>
</head>
<body style="height:2000px">
    <div id="box1"></div>
</body>
</html>
<script>
    /*
        滚轮时 div 变长
    */

    var box1 = document.getElementById("box1");
    box1.onwheel = function(event){

        /*
            event.wheelDelta    ⭐⭐📌
                可以获取鼠标滚轮 滚动方向
                向上滚= 120  向下滚= -120
                wheelDelta 这个值不看大小，只看正负

            event.detail        ⭐⭐📌火狐
                在火狐中使用event.detail 获取滚动方向
                向上滚= -3   向下滚= 3
        */
       
        if (event.wheelDelta > 0 || event.detail <0){ 
            //当滑轮向上滚动时 height -10px 
            box1.style.height = box1.clientHeight - 10 +"px"; 

            // 当 box1 height低于 60px 时，不再缩短
            if(parseInt(box1.style.height) < 60){
                        box1.style.height = 60+"px";
                        // alert(box1.style.height);
                    }
        }else{ 
            //当滑轮向下滚动时  height +10px
            box1.style.height = box1.clientHeight + 10 + "px"; 
        }
        return false;
        
    }
</script>